package com.uzai.console.web.romoteapi;

import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import com.github.xiaoymin.knife4j.annotations.ApiSort;
import com.uzai.common.dto.wxgroup.WxGroupAddBlacklistDto;
import com.uzai.common.exception.BusinessException;
import com.uzai.console.dto.BaseDto;
import com.uzai.console.dto.log.useroperationlog.UserOperationLogByManagerSuperQuery;
import com.uzai.console.dto.md.mdexchange.MdExchangeQuery;
import com.uzai.console.dto.mermobilerecharge.MerMobileRechargeDto;
import com.uzai.console.dto.mermobilerecharge.MerMobileRechargeQuery;
import com.uzai.console.dto.remoteapi.*;
import com.uzai.console.dto.user.blacklist.marketingrewards.MarketingRewardsBlackListOptDto;
import com.uzai.console.dto.wechatprivate.friendrequest.FriendRequestIdListDto;
import com.uzai.console.entity.es.EsUserOperationLog;
import com.uzai.console.enums.OperationTypeEnum;
import com.uzai.console.enums.SystemModelEnum;
import com.uzai.console.service.contract.SysContractService;
import com.uzai.console.service.fd.FdFollowConfigService;
import com.uzai.console.service.log.UserOperationLogService;
import com.uzai.console.service.md.mdexchange.MdExchangeService;
import com.uzai.console.service.mermobilerecharge.MerMobileRechargeService;
import com.uzai.console.service.remoteapi.RemoteApiService;
import com.uzai.console.service.tb.tbpunishorder.TbPunishOrderService;
import com.uzai.console.service.user.MarketingRewardsBlackListService;
import com.uzai.console.service.xxljob.XxlJobSyncService;
import com.uzai.console.vo.base.SelectKeyVo;
import com.uzai.console.vo.md.mdexchange.MdExchangeVo;
import com.uzai.console.vo.mermobilerecharge.MerMobileRechargeVo;
import com.uzai.console.vo.pyq.pyqfollowedcontent.PyqFollowedItemVo;
import com.uzai.console.vo.pyq.pyqjobdetail.PyqJobDetailVo;
import com.uzai.console.vo.remoteapi.cashier.CashierAuthpayContentVo;
import com.uzai.console.vo.remoteapi.reportbanel.ReportBanelFansValueReportVo;
import com.uzai.console.vo.wechatprivate.friendrequest.FriendRequestCountVo;
import com.uzai.console.vo.wechatprivate.friendrequest.FriendRequestInfoVo;
import com.uzai.console.web.BaseController;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.apache.catalina.filters.ExpiresFilter;
import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.servlet.view.RedirectView;

import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import java.util.Objects;

/**
 * 产品
 *
 * @author liuqi
 * @date 2021年08月16日 15:11
 */
@Api(value = "远程接口访问", tags = "远程接口访问")
@ApiSort(100)
@RestController
public class RomoteApiController extends BaseController {
    private Logger logger = LoggerFactory.getLogger(RomoteApiController.class);

    @Autowired
    private RemoteApiService remoteApiService;
    @Autowired
    private MdExchangeService mdExchangeService;
    @Autowired
    private TbPunishOrderService tbPunishOrderService;
    @Autowired
    private MerMobileRechargeService merMobileRechargeService;
    @Autowired
    private XxlJobSyncService xxlJobSyncService;
    @Autowired
    private MarketingRewardsBlackListService marketingRewardsBlackListService;
    @Autowired
    private UserOperationLogService userOperationLogService;
    @Autowired
    private FdFollowConfigService fdFollowConfigService;

    @Autowired
    private SysContractService sysContractService;

    @ApiOperation(value = "发送淘宝订单下载限流报警消息", notes = "发送淘宝订单下载限流报警消息")
    @ApiOperationSupport(order = 1)
    @PostMapping("/sendAlarmMsg/tbOrdersDownLimit")
    public Object sendAlarmMsgTbOrderDownloadLimit(@RequestBody SendAlarmMsgTbOrderDownloadLimitDto sendAlarmMsgTbOrderDownloadLimitDto) {
        //查询新淘宝
        remoteApiService.sendAlarmMsgTbOrderDownloadLimit(sendAlarmMsgTbOrderDownloadLimitDto);
        return true;
    }

    @ApiOperation(value = "悠哉工具箱上传处罚订单", notes = "悠哉工具箱上传处罚订单")
    @ApiOperationSupport(order = 2)
    @PostMapping("/romoteApi/uploadTbPunishOrderByUzaiToolBox")
    public Object uploadTbPunishOrderByUzaiToolBox(@RequestBody UploadTbPunishOrderByUzaiToolBoxDto uploadTbPunishOrderByUzaiToolBoxDto) {
        //查询新淘宝
        tbPunishOrderService.uploadTbPunishOrderByUzaiToolBox(uploadTbPunishOrderByUzaiToolBoxDto);
        return true;
    }

    @ApiOperation(value = "个人微信会员发送消息", notes = "个人微信会员发送消息")
    @ApiOperationSupport(order = 3)
    @PostMapping("/romoteApi/wechatuser/sendMsg")
    public Object wechatUserSendMsg(@RequestBody WechantUserSendMsgDto wechantUserSendMsgDto) {
        remoteApiService.wechatUserSendMsg(wechantUserSendMsgDto);
        return true;
    }

    @ApiOperation(value = "个人微信会员修改备注标签", notes = "个人微信会员修改备注标签")
    @ApiOperationSupport(order = 4)
    @PostMapping("/romoteApi/wechatuser/updateInfo")
    public Object wechatUserUpdateInfo(@RequestBody WechantUserUpdateInfoDto wechantUserUpdateInfoDto) {
        remoteApiService.wechatUserUpdateInfo(wechantUserUpdateInfoDto);
        return true;
    }

    @ApiOperation(value = "个人微信会员修改客户端", notes = "个人微信会员修改客户端")
    @ApiOperationSupport(order = 5)
    @PostMapping("/romoteApi/wechatuser/updateDevice")
    public Object wechatUserUpdateDevice(@RequestBody WechantUserUpdateDeviceDto wechantUserUpdateDeviceDto) {
        remoteApiService.wechatUserUpdateDevice(wechantUserUpdateDeviceDto);
        return true;
    }

    @ApiOperation(value = "账房查询支付链接接口", notes = "账房查询支付链接接口", response = CashierAuthpayContentVo.class)
    @ApiOperationSupport(order = 6)
    @PostMapping("/romoteApi/cashier/getAuthpayContent")
    public Object getCashierAuthpayContent(@RequestBody CashierAuthpayContentDto cashierAuthpayContentDto) {
        return remoteApiService.getCashierAuthpayContent(cashierAuthpayContentDto);
    }

    @ApiOperation(value = "朋友圈查询今日合集接口", notes = "朋友圈查询今日合集接口", response = PyqJobDetailVo.class)
    @ApiOperationSupport(order = 7)
    @PostMapping("/romoteApi/pyq/todaySendList")
    public Object pyqTodaySendList(@RequestBody PyqTodySendListDto pyqTodySendListDto) {
        return remoteApiService.pyqTodaySendList(pyqTodySendListDto);
    }

    @ApiOperation(value = "朋友圈查询明细接口", notes = "朋友圈查询明细接口", response = PyqJobDetailVo.class)
    @ApiOperationSupport(order = 7)
    @PostMapping("/romoteApi/pyq/select/byId")
    public Object pyqTodaySendList(@RequestBody RemoteApiPyqDetailIdDto remoteApiPyqDetailIdDto) {
        return remoteApiService.findPyqDetail(remoteApiPyqDetailIdDto);
    }

    @ApiOperation(value = "粉丝价值报表面板统计接口", notes = "粉丝价值报表面板统计接口", response = ReportBanelFansValueReportVo.class)
    @ApiOperationSupport(order = 6)
    @PostMapping("/romoteApi/reportBanel/fansValueReport")
    public Object reportbanelFansValueReport(@RequestBody ReportPanelFansValueReportQuery reportPanelFansValueReportQuery) {
        return remoteApiService.reportbanelFansValueReprot(reportPanelFansValueReportQuery);
    }

    @ApiOperation(value = "数据面板统计接口", notes = "数据面板统计接口", response = FriendRequestCountVo.class)
    @ApiOperationSupport(order = 6)
    @PostMapping("/romoteApi/dataPanel/data/count")
    public Object dataPanelInfo(@RequestBody DataPanelRemoteQuery query) {
        return remoteApiService.dataPanelInfo(query);
    }

    @ApiOperation(value = "同步微信群管理配置方案id字段到ES缓存中", notes = "同步微信群管理配置方案id字段到ES缓存中", response = Boolean.class)
    @ApiOperationSupport(order = 7)
    @PostMapping("/romoteApi/wxGroupContacts/updateManagePlanIdToEs")
    public Object updateManagePlanIdToEs() {
        remoteApiService.updateManagePlanIdToEs();
        return true;
    }

    @ApiOperation(value = "根据商品id清除自动发送朋友圈历史记录", notes = "根据商品id清除自动发送朋友圈历史记录", response = Boolean.class)
    @ApiOperationSupport(order = 8)
    @PostMapping("/romoteApi/pyqAutoSend/deleteByGoodsid")
    public Object deletePyqAutoSendByGoodsid(@RequestBody PyqAutoSendDeleteDto pyqAutoSendDeleteDto) {
        remoteApiService.deletePyqAutoSendByGoodsid(pyqAutoSendDeleteDto);
        return true;
    }

    @ApiOperation(value = "更新淘宝联盟的mm_user_id", notes = "更新淘宝联盟的mm_user_id", response = Boolean.class)
    @ApiOperationSupport(order = 8)
    @PostMapping("/romoteApi/tbToken/updateMmUserId")
    public Object updateTbTokenMMUserId() {
        remoteApiService.updateTbTokenMMUserId();
        return true;
    }

    @ApiOperation(value = "更新清理僵尸粉任务状态", notes = "更新清理僵尸粉任务状态", response = Boolean.class)
    @ApiOperationSupport(order = 9)
    @PostMapping("/zombieFanTask/updateStatus")
    public Object updateZombieFanTaskStatus(@RequestBody ZombieFanTaskUpdateStatusDto zombieFanTaskUpdateStatusDto) {
        remoteApiService.updateZombieFanTaskStatus(zombieFanTaskUpdateStatusDto);
        return true;
    }

    @ApiOperation(value = "添加个人微信社群黑名单", notes = "添加个人微信社群黑名单", response = Boolean.class)
    @ApiOperationSupport(order = 10)
    @PostMapping("/romoteApi/addBlacklistByWxGroup")
    public Object addBlacklistByWxGroup(@RequestBody WxGroupAddBlacklistDto wxGroupAddBlacklistDto) {
        remoteApiService.addBlacklistByWxGroup(wxGroupAddBlacklistDto);
        return true;
    }

    @ApiOperation(value = "会员添加共享至全网", notes = "会员添加共享至全网", response = Boolean.class)
    @ApiOperationSupport(order = 10)
    @PostMapping("/romoteApi/userBlacklist/sharePub")
    public Object userBlacklistSharePub(@RequestBody UserBlackListSharePubDto userBlackListSharePubDto) {
        remoteApiService.userBlacklistSharePub(userBlackListSharePubDto);
        return true;
    }

    @ApiOperation(value = "会员取消共享至全网", notes = "会员取消共享至全网", response = Boolean.class)
    @ApiOperationSupport(order = 10)
    @PostMapping("/romoteApi/userBlacklist/cancelPub")
    public Object userBlacklistCancelPub(@RequestBody UserBlackListCancelPubDto userBlackListCancelPubDto) {
        remoteApiService.userBlacklistCancelPub(userBlackListCancelPubDto);
        return true;
    }

    @ApiOperation(value = "会员移除私有黑名单 ", notes = "会员移除私有黑名单", response = Boolean.class)
    @ApiOperationSupport(order = 10)
    @PostMapping("/romoteApi/userBlacklist/deletePrv")
    public Object userBlacklistDeletePrv(@RequestBody UserBlackListDeletePrvDto userBlackListDeletePrvDto) {
        remoteApiService.userBlacklistDeletePrv(userBlackListDeletePrvDto);
        return true;
    }

    @ApiOperation(value = "悠聊分页查询好友请求列表", notes = "悠聊分页查询好友请求列表", response = FriendRequestInfoVo.class)
    @ApiOperationSupport(order = 11)
    @PostMapping("/romoteApi/friendRequest/findByPage")
    public Object friendRequestByPage(@RequestBody FriendRequestByUchatRemoteQuery friendRequestByUchatRemoteQuery) {
        return remoteApiService.friendRequestByPage(friendRequestByUchatRemoteQuery);
    }

    @ApiOperation(value = "悠聊通过好友请求", notes = "悠聊通过好友请求", response = Boolean.class)
    @ApiOperationSupport(order = 12)
    @PostMapping("/romoteApi/friendRequest/add")
    public Object addFriendRequest(@RequestBody FriendRequestIdListDto friendRequestIdListDto) {
        remoteApiService.addFriendRequest(friendRequestIdListDto);
        return true;
    }

    @ApiOperation(value = "悠聊忽略好友请求", notes = "悠聊忽略好友请求", response = Boolean.class)
    @ApiOperationSupport(order = 13)
    @PostMapping("/romoteApi/friendRequest/pass")
    public Object passFriendRequest(@RequestBody FriendRequestIdListDto friendRequestIdListDto) {
        remoteApiService.passFriendRequest(friendRequestIdListDto);
        return true;
    }

    @ApiOperation(value = "设置机器人的手机号", notes = "设置机器人的手机号", response = Boolean.class)
    @ApiOperationSupport(order = 14)
    @PostMapping("/romoteApi/device/mobile/set")
    public Object deviceMobileSet(@RequestBody DeviceMobileSetDto deviceMobileSetDto) {
        remoteApiService.deviceMobileSet(deviceMobileSetDto);
        return true;
    }

    @ApiOperation(value = "更新机器人话费余额", notes = "更新机器人话费余额", response = Boolean.class)
    @ApiOperationSupport(order = 14)
    @PostMapping("/romoteApi/device/phonebal/update")
    public Object devicePhonebalUpdate(@RequestBody DevicePhonebalUpdateDto devicePhonebalUpdateDto) {
        remoteApiService.devicePhonebalUpdate(devicePhonebalUpdateDto);
        return true;
    }

    @ApiOperation(value = "查询所有免单兑换记录列表", notes = "查询所有免单兑换记录列表", response = MdExchangeVo.class)
    @ApiOperationSupport(order = 15)
    @PostMapping("/romoteApi/mdExchange/findMdExchangeList")
    public Object findMdExchangeList(@RequestBody MdExchangeQuery mdExchangeQuery) {
        return mdExchangeService.findMdExchangePayList(mdExchangeQuery);
    }

    @ApiOperation(value = "分页查询运营商话费充值记录列表", notes = "分页查询运营商话费充值记录列表", response = MerMobileRechargeVo.class)
    @ApiOperationSupport(order = 16)
    @PostMapping("/romoteApi/merMobileRecharge/findByPage")
    public Object findMerMobileRechargeByPage(@RequestBody MerMobileRechargeQuery merMobileRechargeQuery) {
        return merMobileRechargeService.findMerMobileRechargeByPage(merMobileRechargeQuery);
    }

    @ApiOperation(value = "修改运营商话费充值记录状态", notes = "修改运营商话费充值记录状态", response = Boolean.class)
    @ApiOperationSupport(order = 17)
    @PostMapping("/romoteApi/merMobileRecharge/updateStatus")
    public Object updateMerMobileRechargeStatus(@RequestBody MerMobileRechargeDto merMobileRechargeDto) {
        merMobileRechargeService.updateStatus(merMobileRechargeDto);
        return true;
    }

    @ApiOperation(value = "合并机器人电脑端和移动端授权数据任务", notes = "合并机器人电脑端和移动端授权数据任务", response = Boolean.class)
    @ApiOperationSupport(order = 18)
    @PostMapping("/romoteApi/deviceAuth/handerForPcAndMobile")
    public Object handerDeviceAuthForPcAndMobile() {
        xxlJobSyncService.handerDeviceAuthForPcAndMobile();
        return true;
    }

    @ApiOperation(value = "处理企业微信和个人微信的授权出现多份问题", notes = "处理企业微信和个人微信的授权出现多份问题", response = Boolean.class)
    @ApiOperationSupport(order = 18)
    @PostMapping("/romoteApi/deviceAuth/handerDeviceAuthForWechantAndWxwork")
    public Object handerDeviceAuthForWechantAndWxwork() {
        xxlJobSyncService.handerDeviceAuthForWechantAndWxwork();
        return true;
    }

    @ApiOperation(value = "刷新企业微信授权", notes = "刷新企业微信授权", response = Boolean.class)
    @ApiOperationSupport(order = 18)
    @PostMapping("/romoteApi/deviceAuth/refresh/wxwork")
    public Object refreshDeviceAuthForWxwork() {
        xxlJobSyncService.refreshDeviceAuthForWxwork();
        return true;
    }


    @ApiOperation(value = "添加营销奖励黑名单", notes = "添加营销奖励黑名单", response = Boolean.class)
    @ApiOperationSupport(order = 20)
    @PostMapping("/romoteApi/blacklist/marketingRewards/add")
    public Object add(@RequestBody MarketingRewardsBlackListOptDto optDto) {
        if (Objects.isNull(optDto) || Objects.isNull(optDto.getMerId()) || StringUtils.isBlank(optDto.getWxid())) {
            throw new BusinessException("新增营销黑名单参数错误");
        }
        return marketingRewardsBlackListService.add(optDto);
    }

    @ApiOperation(value = "删除营销奖励黑名单", notes = "删除营销奖励黑名单", response = Boolean.class)
    @ApiOperationSupport(order = 21)
    @PostMapping("/romoteApi/blacklist/marketingRewards/remove")
    public Object remove(@RequestBody MarketingRewardsBlackListOptDto optDto) {
        if (Objects.isNull(optDto) || Objects.isNull(optDto.getId())) {
            throw new BusinessException("删除营销黑名单参数错误");
        }
        return marketingRewardsBlackListService.remove(optDto.getId());
    }

    @ApiOperation(value = "查询朋友圈跟发的商品信息列表", notes = "查询朋友圈跟发的商品信息列表", response = PyqFollowedItemVo.class)
    @ApiOperationSupport(order = 22)
    @PostMapping("/romoteApi/pyqFollowedItem/findByList")
    public Object pyqFollowedItemFindByList(@RequestBody PyqFollowedItemQuery pyqFollowedItemQuery) {
        return remoteApiService.pyqFollowedItemFindByList(pyqFollowedItemQuery);
    }

    @ApiOperation(value = "删除社群群发历史记录", notes = "删除社群群发历史记录", response = Boolean.class)
    @ApiOperationSupport(order = 23)
    @PostMapping("/romoteApi/fdSendJob/deleteHistory")
    public Object deleteHistoryFdSendJob() {
        remoteApiService.deleteHistoryFdSendJob();
        return true;
    }

    @ApiOperation(value = "通过被动僵尸粉添加", notes = "通过被动僵尸粉添加", response = Boolean.class)
    @ApiOperationSupport(order = 24)
    @PostMapping("/romoteApi/zombieFanPassive/pass")
    public Object passZombieFanPassive(@RequestBody PassZombieFanPassiveDto passZombieFanPassiveDto) {
        remoteApiService.passZombieFanPassive(passZombieFanPassiveDto);
        return true;
    }

    @ApiOperation(value = "远程分页查询客服超级账号操作日志列表", notes = "分页查询客服超级账号操作日志列表", response = EsUserOperationLog.class)
    @ApiOperationSupport(order = 25)
    @PostMapping("/romoteApi/managerSuperAccount/findUserOperationLogList")
    public Object findUserOperationLogListByKefuManage(@RequestBody UserOperationLogByManagerSuperQuery userOperationLogByManagerSuperQuery) {
        return userOperationLogService.findUserOperationLogListByKefuManage(userOperationLogByManagerSuperQuery);
    }

    @ApiOperation(value = "远程查询操作模块下拉列表", notes = "查询操作模块下拉列表", response = SelectKeyVo.class)
    @ApiOperationSupport(order = 26)
    @PostMapping("/romoteApi/userOperationLog/findModelList")
    public Object findModelList() {
        List<SelectKeyVo> selectKeyVoList = new ArrayList<>();
        //先封装主账号
        SystemModelEnum[] systemModelEnumArr = SystemModelEnum.values();
        if (systemModelEnumArr != null) {
            for (SystemModelEnum systemModelEnum : systemModelEnumArr) {
                SelectKeyVo selectKeyVo = new SelectKeyVo();
                selectKeyVo.setKey(systemModelEnum.getKey());
                selectKeyVo.setValue(systemModelEnum.getDesc());
                selectKeyVoList.add(selectKeyVo);
            }
        }
        return selectKeyVoList;
    }

    @ApiOperation(value = "远程查询操作类型下拉列表", notes = "查询操作类型下拉列表", response = SelectKeyVo.class)
    @ApiOperationSupport(order = 27)
    @PostMapping("/romoteApi/userOperationLog/findTypelList")
    public Object findTypelList() {
        List<SelectKeyVo> selectKeyVoList = new ArrayList<>();
        //先封装主账号
        OperationTypeEnum[] operationTypeEnumArr = OperationTypeEnum.values();
        if (operationTypeEnumArr != null) {
            for (OperationTypeEnum operationTypeEnum : operationTypeEnumArr) {
                SelectKeyVo selectKeyVo = new SelectKeyVo();
                selectKeyVo.setKey(operationTypeEnum.getKey());
                selectKeyVo.setValue(operationTypeEnum.getDesc());
                selectKeyVoList.add(selectKeyVo);
            }
        }
        return selectKeyVoList;
    }

    @ApiOperation(value = "远程调用更新是否下载大图的群列表", notes = "远程调用更新是否下载大图的群列表", response = String.class)
    @ApiOperationSupport(order = 28)
    @PostMapping("/romoteApi/refresh/downloadImgGroupWxidList")
    public Object refreshDownloadImgGroupWxidList(@RequestBody RefreshDownloadImgGroupWxidListDto refreshDownloadImgGroupWxidListDto) {
        return fdFollowConfigService.refreshDownloadImgGroupWxidList(refreshDownloadImgGroupWxidListDto);
    }

    @ApiOperation(value = "远程调用回调合同签约状态", notes = "远程调用回调合同签约状态", response = Boolean.class)
    @ApiOperationSupport(order = 28)
    @GetMapping("/romoteApi/callback/updateContractAndReturn")
    public void updateContractAndReturn(@RequestParam("signFlowId") String signFlowId, HttpServletResponse httpServletResponse) throws IOException {
        sysContractService.updateContractAndReturn(signFlowId,httpServletResponse);

    }

}
